# encoding: utf-8

namespace :check do
  task release: :environment do
    (Installation.all+Terminal.all).each do |i|
      if !i.release 
        if i.release_time < Date.tomorrow
          title = "#{i.display_name} #{i.version} 需要及时发布"
          body = "大家好， 系统检测到#{i.display_name} #{i.version} 需要在明天发布， 请相关人员及时做好准备"
          email = AdminMailer.release_notify(title, body, i.staff_emails).deliver
          puts "sned email: Date.tomorrow need release"
        elsif i.release_time < Time.now
          title = "#{i.display_name} #{i.version} 需要及时发布"
          body = "大家好， 系统检测到#{i.display_name} #{i.version}未按计划的时间发布， 请尽快完成测试并发布"
          email = AdminMailer.release_notify(title, body, i.staff_emails).deliver
          puts "send email: today need release"
        end
      end
    end
  end
end
